package com.cskaoyan.exception;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 生效：只需要注册到容器中就生效
 * @author stone
 * @date 2022/12/26 17:15
 */
//@Component
public class CustomHandlerExceptionResolver implements HandlerExceptionResolver {
    /**
     *
     * @param handler 抛出异常的Handler
     * @param exception Handler抛出的异常
     * @return
     */
    @Override
    public ModelAndView resolveException(HttpServletRequest httpServletRequest,
                                         HttpServletResponse httpServletResponse,
                                         Object handler, Exception exception) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/exception.jsp");
        // 如果想要响应字符串或Json字符串可以不？可以 → 第二个参数是什么
        return modelAndView;
    }
}
